//
//  RemarkViewCell.m
//  Guazi
//
//  Created by koolearn on 11-7-31.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "RemarkViewCell.h"
#import "DateUtils.h"


@implementation RemarkViewCell

@synthesize remark;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIColor* backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = backgroundColor;
        
        screenNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        screenNameLabel.backgroundColor = backgroundColor;
        screenNameLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:screenNameLabel];
        
        messageLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        messageLabel.backgroundColor = backgroundColor;
        messageLabel.textAlignment = UITextAlignmentRight;
        messageLabel.font = [UIFont systemFontOfSize:13];
        messageLabel.textColor = [UIColor colorWithRed:0.5f green:0.5f blue:0.5f alpha:1.0f];
        [self.contentView addSubview:messageLabel];
        
        remarkLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        remarkLabel.font = [UIFont systemFontOfSize:14];
        remarkLabel.backgroundColor = backgroundColor;
        [self.contentView addSubview:remarkLabel];
    }
    return self;
}


- (void) setRemark:(Remark *)r
{
    remark = [r retain];
    screenNameLabel.text = remark.user.screenName;
    messageLabel.text = [DateUtils diffNowString:remark.createAt];
    remarkLabel.text = remark.text;
}


- (void) layoutSubviews
{
    screenNameLabel.frame = CGRectMake(10, 5, 80, 20);
    messageLabel.frame = CGRectMake(80, 5, 220, 20);
    
    CGSize size = [remark.text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 600) lineBreakMode:UILineBreakModeCharacterWrap];
    remarkLabel.frame = CGRectMake(10, 25, 300, size.height);
    [super layoutSubviews];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [screenNameLabel release];
    [messageLabel release];
    [remarkLabel release];
    [remark release];
    [super dealloc];
}

@end
